package com.rsk.api;



import com.alibaba.dubbo.config.annotation.Reference;
import com.rsk.api.common.ReturnUtils;
import com.rsk.service.SysParamsConfigService;
import com.rsk.utils.result.Result;
import com.rsk.utils.result.ResultBuilder;
import com.rsk.utils.result.ResultCode;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.ws.rs.QueryParam;
import java.util.List;
import java.util.Map;

/**
 * @author myr
 * @date 2020/1/14
 *
 * 数据字典 参数配置 信息操作处理
 *
 */


@RestController
@RequestMapping(value="/sys/paramsConfig")
public class SystemParamsConfigApi {


    @Reference(interfaceClass = SysParamsConfigService.class,protocol = "dubbo")
    private SysParamsConfigService sysParamsConfigService;


    /**
     * 查看参数：数据字典
     */
    //@RequiresPermissions("sys_paramsConfig:select")
    @PostMapping("selectSysParamsConfig")
    public Result<List<Map<String, Object>>> selectSysParamsConfig(@QueryParam("paramName") String paramName,
                                                                   @QueryParam("paramCode") String paramCode,
                                                                   @RequestHeader("Authorization") String Authorization){
        //数据校验
        //String operatorUser = JwtUtil.getClaim(Authorization, "account");
        Long operatorUser = 123L;
        List<Map<String, Object>> list = sysParamsConfigService.selectSysParamsConfig(paramName,paramCode);
        return ResultBuilder.success(list,ResultCode.SUCCESS);
    }

    /**
     * 新增参数
     * @return
     */

    //@RequiresPermissions("sys_users:save")
    @PostMapping("/addSysParamsConfig")
    public Result<String> addSysParamsConfig(@QueryParam("paramName") String paramName,
                                             @QueryParam("paramCode") String paramCode,
                                             @QueryParam("Id") Long Id,
                                             @RequestHeader("Authorization") String Authorization){
        //数据校验
        //String operatorUser = JwtUtil.getClaim(Authorization, "account");
        Long operatorUser = 123L;
        int i = sysParamsConfigService.saveSysParamsConfig(paramName,Id,paramCode,operatorUser);
        return ReturnUtils.returnDataByOne(i);
    }


    /**
     * 删除参数
     */

    //@RequiresPermissions("sys_users:save")
    @PostMapping("/delSysParamsConfig")
    public Result<String> delSysParamsConfig(@QueryParam("Id") Long Id,
                                             @RequestHeader("Authorization") String Authorization){
        //数据校验
        //String operatorUser = JwtUtil.getClaim(Authorization, "account");
        Long operatorUser = 123L;
        int i = sysParamsConfigService.delSysParamsConfig(Id,operatorUser);
        return ReturnUtils.returnDataByOne(i);
    }

    /**
     *修改参数
     */
    //@RequiresPermissions("sys_users:save")
    @PostMapping("/updateSysParamsConfig")
    public Result<String> updateSysParamsConfig(@QueryParam("Id") Long Id,
                                                @QueryParam("paramName") String paramName,
                                                @RequestHeader("Authorization") String Authorization){
        //数据校验
        //String operatorUser = JwtUtil.getClaim(Authorization, "account");
        Long operatorUser = 123L;
        int i = sysParamsConfigService.updateSysParamsConfig(Id,paramName,operatorUser);
        return ReturnUtils.returnDataByOne(i);
    }

}
